package cn.le.container;

import java.util.SortedSet;
import java.util.concurrent.ConcurrentSkipListSet;

/**
 * SortedSet中的元素可以保证处于排序状态
 *
 * 已知实现类:ConcurrentSkipListSet, TreeSet
 *
 */
public class SortedSetCS {

    public static void main(String[] args) {

        SortedSet<Integer> set = new ConcurrentSkipListSet();

        set.add(1);
        set.add(2);
        set.add(4);
        set.add(3);

       // System.out.println(set.first());
       // System.out.println(set.last());

        set.comparator();
/*
        for (Integer iter : set) {
            System.out.println(iter);
        }*/

        SortedSet<B> setB = new ConcurrentSkipListSet();

        setB.add(new B(3));
        setB.add(new B(1));
        setB.add(new B(2));
        setB.add(new B(4));

        System.out.println("size"+setB.size());

        //setB.comparator();
        for (B iter : setB) {
            System.out.println(iter.age);
        }

    }

}

class B implements Comparable{

    int age;

    public B(int age)
    {
        this.age = age;
    }

    @Override
    public int compareTo(Object o) {

        B b = (B) o;
        System.out.println("b.age:"+b.age);
        //b.age - this.age 降序
        //this.age - b.age 升序
        return b.age - this.age;
    }
}